//
//  Balloon.m
//  JiuLe
//
//  Created by 黄鑫 on 16/8/26.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "Balloon.h"


@implementation Balloon

- (void)showTips:(NSString *)info{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];//(CGRect) {{0.f, 0.f}, [[UIScreen mainScreen] bounds].size}
    window.backgroundColor =  [[UIColor blackColor] colorWithAlphaComponent:0.5];
    window.windowLevel = UIWindowLevelNormal;
    window.hidden = NO;
    CGSize size =[info sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    NSInteger space = 65;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width + space, 58)];
    view.backgroundColor = [UIColor whiteColor];
    view.alpha = 0.8;
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 8;
    UILabel *labInfo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), size.height)];
    labInfo.text = info;
    labInfo.textAlignment = NSTextAlignmentCenter;
    labInfo.center = view.center;
    [view addSubview:labInfo];
    [window addSubview:view];
    view.center = window.center;
    __sheetWindow = window;
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.5
                                                       target:self
                                                     selector:@selector(removeWindowAction)
                                                    userInfo:nil
                                                        repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

//显示激活成功
- (void)showActivationSuccessful:(NSString *)info{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    window.backgroundColor =  [[UIColor blackColor] colorWithAlphaComponent:0.5];
    window.windowLevel = UIWindowLevelNormal;
    window.hidden = NO;
    CGSize size =[info sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    NSInteger space = 65;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width + space + size.height, 58)];
    view.backgroundColor = [UIColor whiteColor];
    view.alpha = 0.8;
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 8;
    
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_check"]];
    image.frame = CGRectMake(15, (58 - size.height)/2, size.height, size.height);
    
    UILabel *labInfo = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image.frame), (58 - size.height)/2, 160, size.height)];
    labInfo.text = info;
    labInfo.textAlignment = NSTextAlignmentCenter;
    [view addSubview:image];
    [view addSubview:labInfo];
    [window addSubview:view];
    view.center = window.center;
    __sheetWindow = window;
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:1.5
                                                       target:self
                                                     selector:@selector(removeWindowAction)
                                                     userInfo:nil
                                                      repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}


-(void)removeWindowAction{
    __sheetWindow.hidden = YES;
    __sheetWindow = nil;
}
@end
